
package com.scs.application.modules.base.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.mvc.controller.ImAndExAbleController;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.base.entity.HospitalNotice;
import com.scs.application.modules.base.request.HospitalNoticeQueryRequest;
import com.scs.application.modules.base.service.HospitalNoticeService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 群发供应商 controller
 */
@AllArgsConstructor
@RestController
@RequestMapping("/base/hospital_notices")
public class HospitalNoticeController extends CrudController<HospitalNotice, String, HospitalNoticeService> implements ImAndExAbleController<HospitalNoticeQueryRequest> {

    private final HospitalNoticeService hospitalNoticeService;

    @GetMapping("/page")
    public PageResult page(HospitalNoticeQueryRequest request) {
        IPage page = service.page(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }

    @GetMapping("/list")
    public CommonResult list(HospitalNoticeQueryRequest request) {
        List<HospitalNotice> list = service.list(request);
        return CommonResult.ok("查询成功", list);
    }

    @PostMapping("/save_msg")
    public CommonResult saveMsg(@RequestBody @Valid HospitalNotice entity) {
        entity.setHospitalId(UserUtils.getHospitalId());
        Boolean bSave = hospitalNoticeService.saveMsg(entity);
        return bSave ? CommonResult.ok("保存成功", entity) : CommonResult.error("保存失败");
    }

    @PostMapping("/update_is_send")
    public CommonResult updateIsSend(@RequestBody @Valid HospitalNotice entity) {
        hospitalNoticeService.updateIsSendById(entity);
        return CommonResult.ok("消息发送成功");
    }


}
